#include "EE.h"

pfdl_descriptor_t 	pfdl_descriptor;
pfdl_request_t  	pfdl_request;
pfdl_status_t		pfdl_status;       
pfdl_command_t  	pfdl_command;


void Error_Hander(void)
{
	__nop();
}

void PFDL_Init(void)
{
	pfdl_descriptor.fx_MHz_u08 = 16;        
	pfdl_descriptor.wide_voltage_mode_u08 = 0;  
	pfdl_status = PFDL_Open((__near pfdl_descriptor_t*) &pfdl_descriptor);   
	while(pfdl_status !=PFDL_OK)
	{
		Error_Hander();           
	}
}
unsigned char PFDL_BlankCheck(unsigned int Flash_index,unsigned int Length)
{
	pfdl_request.index_u16 = Flash_index;        
	pfdl_request.bytecount_u16 = Length;   
	pfdl_request.command_enu = PFDL_CMD_BLANKCHECK_BYTES;  
	pfdl_status = PFDL_Execute(&pfdl_request);       
	do 
	{
		pfdl_status = PFDL_Handler();
	}
	while(pfdl_status == PFDL_BUSY);      
	return(pfdl_status);   
}

void PFDL_Erase(unsigned int Flash_index)     
{
	pfdl_request.index_u16   = Flash_index;           
	pfdl_request.command_enu = PFDL_CMD_ERASE_BLOCK;
	pfdl_status = PFDL_Execute(&pfdl_request);            
	do 
	{
		pfdl_status = PFDL_Handler();
	}
	while(pfdl_status == PFDL_BUSY);     
	if (pfdl_status != PFDL_OK) 
	{
		Error_Hander();      
	} 
}
 
void PFDL_Write(unsigned int Flash_index,pfdl_u08* w_buff, unsigned int Data_Count)
{
	pfdl_request.index_u16   = Flash_index;   
	pfdl_request.data_pu08   = w_buff;       
	pfdl_request.bytecount_u16  = Data_Count;    
	pfdl_request.command_enu  = PFDL_CMD_WRITE_BYTES;   
	pfdl_status = PFDL_Execute(&pfdl_request);        
	do 
	{
		pfdl_status = PFDL_Handler();
	}
	while(pfdl_status == PFDL_BUSY);      
	if(pfdl_status != PFDL_OK)  
	Error_Hander();           
}

unsigned char PFDL_Iverify(unsigned int Flash_index,unsigned int Length)
{
	pfdl_request.index_u16   = Flash_index;          
	pfdl_request.bytecount_u16  = Length;    
	pfdl_request.command_enu  = PFDL_CMD_IVERIFY_BYTES;   
	pfdl_status = PFDL_Execute(&pfdl_request); 
	return (pfdl_status);       
}


unsigned char PFDL_Read(unsigned int Flash_index,pfdl_u08* R_DataFla_buff,unsigned int Data_Count)
{
	pfdl_request.index_u16 = Flash_index;    
	pfdl_request.data_pu08 = R_DataFla_buff;        
	pfdl_request.bytecount_u16 = Data_Count;     
	pfdl_request.command_enu = PFDL_CMD_READ_BYTES;    
	pfdl_status = PFDL_Execute(&pfdl_request);        
	do 
	{
		pfdl_status = PFDL_Handler();
	}
	while(pfdl_status == PFDL_BUSY);         
	return (pfdl_status);
}






